<%@page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@include file="/common/session.jsp"%>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=2.0, user-scalable=no, width=device-width">
    <LINK type="text/css" rel="stylesheet" href="${ctx}/css/default.css"/>
    <script type="text/javascript" src="${ctx}/js/xtable.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/engine.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/util.js"></script>
    <script type='text/javascript' src='${ctx}/dwr/interface/RotationRpcService.js'></script>
    <script type='text/javascript' src='${ctx}/dwr/interface/MarketRpcService.js'></script>
    <script type="text/javascript" src="${ctx}/js/loading.js"></script>
</head>
<body>
<form>
	<center>
        <table style="width: 50%;" cellpadding="5" cellspacing="5">
            <tr>
                <td>
                    <select id="marketId" name="marketId" onchange="getRotationPage()">
			            <option value="">所属市场</option>
			        </select>
                </td>
                <td>
                    <button type="button" onclick="submitRotation('')">新增轮播图</button>
                </td>
            </tr>
        </table>
    </center>
</form>

<SCRIPT LANGUAGE="JavaScript" >
    var rotationThead = new Array(
        new XThead("图片名称"),
        new XThead("缩略图"),
        new XThead("图片链接"),
        new XThead("排序"),
        new XThead("所属市场"),
        new XThead("图片状态"),
        new XThead("操作")
    );

    var rotationXTable = new XTable("rotation", rotationThead, true);

    rotationXTable.XTbodyArray = function (model) {
        var array = new Array(
            new XTbody("rotation", model.rotationName,"string", null, null, "center"),
            new XTbody("rotation", "<img src='${fdfsPath}"+model.rotationImage+".w_100xh_100' />","string", null, null, "center"),
            new XTbody("rotation", model.rotationUrl,"string", null, null, "center"),
            new XTbody("rotation", model.rotationSeq, "string", null, null, "center"),
            new XTbody("rotation", model.market.marketName, "string", null, null, "center"),
            new XTbody("rotation", model.rotationState==1?"有效":"无效","string", null, null, "center"),
            new XTbody("rotation", model.rotationState==1?"<a href='#' style='border-right: 1px solid #dddddd' onclick=submitRotation('"+ model.rotationId +"')>编辑&nbsp;</a>"+"<a href='#' onclick=repealRotation('"+ model.rotationId +"')>&nbsp;撤销</a>":
            	"<a href='#' style='border-right: 1px solid #dddddd' onclick=submitRotation('"+ model.rotationId +"')>编辑&nbsp;</a>"+"<a href='#' onclick=recoverRotation('"+ model.rotationId +"')>&nbsp;恢复</a>", 
             	"string", null, null, "center")
        );
        return array;
    }
    
    function getRotationPage() {
        var rotation = new Rotation();
        rotation.marketId = dwr.util.getValue("marketId");
        RotationRpcService.selectRotationList(rotation, function (list) {
        	rotationXTable.addTable(list);
        }); 
    }

</SCRIPT>
</body>
</html>
<script>
	var market = new Market();
	market.marketId = "${marketId}";
	MarketRpcService.selectMarketList(market, callbackSelectMarketList);

	function callbackSelectMarketList(list) {
	    dwr.util.addOptions("marketId", list, "marketId", "marketName");
	    dwr.util.setValue("marketId", "${marketId}");
	    getRotationPage();
	}
	
    function submitRotation(rotationId){
        location = "${ctx}/cms/rotation_manage.jsp?rotationId=" + rotationId;
    }
    
    function repealRotation(rotationId){
    	if (rotationId == null || rotationId == '') {
            return false;
        }
    	
    	if(confirm('确定要撤销吗？')){
    		var rotation = new Rotation();
    		rotation.rotationId = rotationId;
    		rotation.rotationState = 0;
    		RotationRpcService.updateRotation(rotation, callbackUpdateRotation);
    	}else{
    		return false;
    	}
    }
    
    function recoverRotation(rotationId){
    	if (rotationId == null || rotationId == '') {
            return false;
        }
    	
    	if(confirm('确定要恢复吗？')){
    		var rotation = new Rotation();
    		rotation.rotationId = rotationId;
    		rotation.rotationState = 1;
    		RotationRpcService.updateRotation(rotation, callbackUpdateRotation);
    	}else{
    		return false;
    	}
    }
    
    function callbackUpdateRotation(data){
    	if(data){
    		alert('操作成功!');
    		location.reload();
    	}
    }
    
</script>
